package com.service.setting.impl;

import com.comm.R;
import com.entity.InspectionItem;
import com.github.pagehelper.PageHelper;
import com.mapper.setting.SystemInspectionMapper;
import com.service.setting.SystemInspectionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class SystemInspectionServiceimpl implements SystemInspectionService {

   @Autowired
    private SystemInspectionMapper mapper;
    @Override
    public R fundInspection(String itemName) {
            R r = new R();
            try {
                InspectionItem inspectionItem = mapper.fundInspection(itemName);
                if (inspectionItem!=null){
                    r.setCode(200);
                    r.setMsg("查询成功");
                    r.setData(inspectionItem);
                    return r;
                }else {
                    r.setCode(200);
                    r.setMsg("查询失败，检查后再输入！！！");
                    return r;
                }
            }catch (Exception e){
                e.printStackTrace();
                r.setCode(500);
                r.setMsg("服务器开小差了！！");
                return r;
            }

    }

    @Override
    public R fundInspections(Integer currentPage,Integer pageSize) {
        R r = new R();
        try {
            com.github.pagehelper.Page<InspectionItem> page = PageHelper.startPage(currentPage,pageSize);
            List<InspectionItem> inspectionItems = mapper.fundInspections();
            int fundcount = mapper.fundcount();
            r.setCode(200);
                r.setMsg("查询成功");
                r.setData(inspectionItems);
                r.setCount(fundcount);
                return r;
        }catch (Exception e){
            e.printStackTrace();
            r.setCode(500);
            r.setMsg("服务器开小差了！！");
            return r;
        }

    }

    @Override
    public R addInspection(InspectionItem inspectionItem) {
        R r = new R();
        try {
            int i = mapper.addInspection(inspectionItem);
                r.setCode(200);
                r.setMsg("添加成功:)");
                return r;
        }catch (Exception e){
            e.printStackTrace();
            r.setCode(500);
            r.setMsg("服务器开小差了！！");
            return r;
        }
    }

    @Override
    public R editInspection(InspectionItem inspectionItem) {
        R r = new R();
        try {
            int i = mapper.editInspection(inspectionItem);
            r.setCode(200);
            r.setMsg("修改成功:)");
            return r;

        }catch (Exception e){
            e.printStackTrace();
            r.setCode(500);
            r.setMsg("服务器开小差了！！");
            return r;

        }
    }

    @Override
    public R delInspection(Integer id) {
        R r = new R();
        try {
            int i = mapper.delInspection(id);
            r.setCode(200);
            r.setMsg("删除成功:)");
            return r;

        } catch (Exception e) {
            e.printStackTrace();
            r.setCode(500);
            r.setMsg("服务器开小差了！！");
            return r;

        }
    }
}
